import java.util.Random;
import java.util.ArrayList;

// 主类 Animal
public class Animal {
    public static void main(String[] args) {
        Random rand = new Random(); // 初始化随机数发生器

        ArrayList<AnimalBase> animals = new ArrayList<AnimalBase>(10); // 创建一个长度为10的动物数组
        for (int i = 0; i < 10; ++i) {
            int randomAnimal = rand.nextInt(4); // 随机选择一种动物
            switch (randomAnimal) {
                case 0:
                    animals.add(new Tiger("Tiger"));
                    break;
                case 1:
                    animals.add(new Elephant("Elephant"));
                    break;
                case 2:
                    animals.add(new Fox("Fox"));
                    break;
                case 3:
                    animals.add(new Panda("Panda"));
                    break;
            }
        }

        for (AnimalBase animal : animals) {
            animal.makeSound();
        }

        // Java中的垃圾回收器会自动清理不再使用的对象，所以不需要手动删除对象
    }
}

// 基类 AnimalBase
abstract class AnimalBase {
    String name;

    public AnimalBase(String name) {
        this.name = name;
    }

    // 抽象方法
    public abstract void makeSound();
}

// 子类 Tiger
class Tiger extends AnimalBase {

    public Tiger(String name) {
        super(name);
    }

    @Override
    public void makeSound() {
        System.out.println("Tiger: Roar!");
    }
}

// 子类 Elephant
class Elephant extends AnimalBase {

    public Elephant(String name) {
        super(name);
    }

    @Override
    public void makeSound() {
        System.out.println("Elephant: Trumpet!");
    }
}

// 子类 Fox
class Fox extends AnimalBase {

    public Fox(String name) {
        super(name);
    }

    @Override
    public void makeSound() {
        System.out.println("Fox: Chirp!");
    }
}

// 子类 Panda
class Panda extends AnimalBase {

    public Panda(String name) {
        super(name);
    }

    @Override
    public void makeSound() {
        System.out.println("Panda: Squeak!");
    }
}
